package com.sino.androiddesign.recyclerviewdemo


import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v7.widget.DefaultItemAnimator
import android.support.v7.widget.LinearLayoutManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup

import com.sino.androiddesign.R
import kotlinx.android.synthetic.main.fragment_add_or_remove_anim.*
import kotlinx.android.synthetic.main.fragment_switch_item_delete.*


/**
 * 添加或删除动画
 *
 */
class AddOrRemoveAnimFragment : Fragment() {

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_add_or_remove_anim, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        anim_rv.layoutManager= LinearLayoutManager(context)
        var datas = ArrayList<String>()
        for (i  in 0 until 40){
            datas.add("test$i")
        }
        anim_rv.adapter = SwitchAdapter(context!!,datas)
        anim_rv.addItemDecoration(CustomDividerLine(context!!,CustomDividerLine.LINE_HORIZONTAL))

        //默认动画   可以根据这个去仿写
        var defaultItemAnimator = DefaultItemAnimator()
        defaultItemAnimator.addDuration = 1000
        defaultItemAnimator.removeDuration = 1000
        anim_rv.itemAnimator =defaultItemAnimator

        anim_add_btn.setOnClickListener {
            datas.add(3,"添加")
            anim_rv.adapter.notifyItemInserted(3)
        }
        anim_remove_btn.setOnClickListener{
            datas.removeAt(0)
            anim_rv.adapter.notifyItemRemoved(0)
        }
    }
}
